
<template>
  <div class="home">
    <el-container>
      <el-header>
        <h1>管理平台</h1>
        <div class="you">
          欢迎:{{ username }}
          <el-button @click="backLogin">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '68px' : '200px'">
          <p class="guan" @click="isCollapse = !isCollapse">
            <i class="el-icon-s-operation"></i>
          </p>
          <el-menu
            :collapse="isCollapse"
            :default-active="$route.path.slice(1)"
            class="el-menu-vertical-demo"
            background-color="#373d41"
            text-color="#fff"
            router
            active-text-color="#ffd04b"
            :collapse-transition="false"
          >
            <el-submenu
              :index="item.id + ''"
              v-for="(item, index) in menusList"
              :key="index"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group v-for="(ele, i) in item.children" :key="i">
                <el-menu-item :index="'/' + ele.path">{{
                  ele.authName
                }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item
              v-for="(item, index) in $route.meta.list"
              :key="index"
              ><a href="/">{{ item.title }}</a></el-breadcrumb-item
            >
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getMenus } from "../http/user";
export default {
  name: "",
  components: {},
  data() {
    return {
      menusList: [],
      isCollapse: false,
      username: localStorage.getItem("houtaiusername"),
    };
  },
  created() {
    getMenus().then((res) => {
      console.log(res);
      this.$message({
        message: "获取菜单列表成功",
        type: "success",
      });
      this.menusList = res.data;
    });
  },
  mounted() {},
  methods: {
    // 退出
    backLogin() {
      this.$router.push("/login");
      this.$store.commit("user/DEL_TOKEN");
      this.$store.commit("user/DEL_USERNAME");
    },
  },
};
</script>
<style scoped lang='scss'>
.el-header,
.el-footer {
  background-color: #373d41;
  color: #fff;
  display: flex;
  justify-content: space-between;
  line-height: 60px;
  box-sizing: border-box;
}

.el-aside {
  background-color: #373d41;
  color: #fff;
  text-align: center;
   box-sizing: border-box;
  height: calc(100vh - 60px);
  .guan {
    background-color: #4a5064;
  }
}

.el-main {
  background-color: #d3dce6;
  color: #333;
  height: calc(100vh - 60px);
  box-sizing: border-box;
}
</style>

